/****************************************************
          File Name:link.c
          Author: Abby Cin
          Mail: abbytsing@gmail.com
          Created Time: Mon 13 Oct 2014 09:50:51 PM CST
*****************************************************/

#include "list.h"

void err(char *fun)
{
    perror(fun);
    exit(errno);
}

int main(int argc, char *argv[])
{
    Node *root;
    int store;

    root = NULL;

    printf("how long a list will create:\n");
    scanf("%d",&store);

/***********    create a list   ***********/
    root = lcreate(store);

    printf("show list:\n");
    show(root);

/************     insert element       ***********/
    printf("input where to insert:\n");
    scanf("%d",&store); 

	if(isInlist(root,store)==1)
	{
		puts("value already in list");
		err("isInlist");
	}
	if(insert(&root,store) == -1)
		err("insert");

    printf("show list:\n");
    show(root);

/***********     delete element     ***********/
    printf("input where to delete:\n");
    scanf("%d",&store);
    if(delete(&root,store) == -1)
        err("delete");

    printf("show list:\n");
    show(root);

/********    show length    **********/
    printf("list's length : %d\n",len(root));


/******* 	modify		***************/
	int new_value;
	printf("enter where to modify:");
	scanf("%d",&store);
	printf("enter new_value:");
	scanf("%d",&new_value);
	modify(root,store,new_value);
	
	printf("show list:\n");
    show(root);

/***********  rank *****************/
    printf("rank from small to large:\n");
    Node *tmp;
    tmp=lrank(root, "");
	printf("show list:\n");
    show(tmp);
/*********		destroy list 		*****/
    printf("destroy list!\n");
    destroy(root);
    return 0;
}
